package com.two.commodityorder.service.impl;// 商品服务实现类

import com.two.commodityorder.dao.CommodityDao;
import com.two.commodityorder.dao.impl.CommodityDaoImpl;
import com.two.commodityorder.model.Commodity;
import com.two.commodityorder.service.CommodityService;
import java.util.List;

public class CommodityServiceImpl implements CommodityService {
	@Override
	public List<Commodity> selectAllCommodity() {
		CommodityDao dao = new CommodityDaoImpl();
		return dao.selectAllCommodity();
	}

	@Override
	public boolean LoginCommodityServlet(String commodityName, String price) {
		CommodityDao dao = new CommodityDaoImpl();
		Commodity u = dao.selectByCommodityName(commodityName);
		if(u != null && u.getProductName().equals(commodityName)&&u.getPrice().equals(price)) {
			return true;
		}
		return false;
	}

	@Override
	public Commodity selectByCommodityId(String id) {
		CommodityDao dao = new CommodityDaoImpl();
		int no = Integer.valueOf(id);
		return dao.selectByCommodityId(no);
	}

	@Override
	public boolean AddCommodity(String commodityName, String price) {
		CommodityDao dao = new CommodityDaoImpl();
		int n = dao.AddCommodity(commodityName, price);
		return n>0;
	}

	@Override
	public boolean UpdateCommodity(String  id, String commodityName, String price) {
		CommodityDao dao = new CommodityDaoImpl();
		int i = Integer.valueOf(id);
		int n = dao.UpdateCommodity(i, commodityName, price);
		return n>0;
	}

	@Override
	public boolean DeleteCommodity(String id) {
		CommodityDao dao = new CommodityDaoImpl();
		int i = Integer.valueOf(id);
		int n = dao.DeleteCommodity(i);
		return n>0;
	}

	@Override
	public boolean selectByCommodityName(String commodityName) {
		CommodityDao dao = new CommodityDaoImpl();
		Commodity u = dao.selectByCommodityName(commodityName);
		if(u != null && u.getProductName().equals(commodityName)) {
			return true;
		}
		return false;
	}

		
	}